<template>
    <div class="musicList">
        <div class="musicTop">
            <div class="title">发现好歌单</div>
            <div class="more">查看更多</div>
        </div>
        <div class="musicSwipe">
            <van-swipe :loop="false" :width="150" class="my-swipe" :show-indicators="false">
                <van-swipe-item v-for="item in state.musicList" :key="item">
                    <router-link :to="{path:'/itemMusic',query:{id:item.id}}">
                        <img :src="item.picUrl" alt=""/>
                        <span class="playCount">
                            <span class="iconfont">&#xe6cf;</span>
                            {{ changeCount(item.playCount) }} 
                        </span>
                        <span class="name">{{item.name}}</span>
                    </router-link>
                </van-swipe-item>
            </van-swipe>
        </div>
    </div>
</template>

<script>
import { getMusicList } from "@/request/api/home.js"
import { reactive,onMounted } from 'vue';
export default{
    // data() {
    //     return {
    //         musicList: []
    //     }
    // },
    // methods: {
    //     async getMusician() {
    //         let res = await getMusicList();
    //         console.log(res);
    //         this.musicList = res.data.result;
    //     },
    //     changeCount: function (num) {
    //         if (num >= 100000000) {
    //             return (num / 100000000).toFixed(1) + "亿";
    //         } else if(num >= 10000){
    //             return (num / 10000).toFixed(1) + "万";
    //         }
    //     }
    // },
    // mounted() {
    //     this.getMusician();
    // }
    setup() {
        const state = reactive({
            musicList: [],
        })
        function changeCount(num) {
            if (num >= 100000000) {
                return (num / 100000000).toFixed(1) + "亿";
            } else if(num >= 10000){
                return (num / 10000).toFixed(1) + "万";
            }
        }
        onMounted(async () => {
            let res = await getMusicList();
            console.log(res);
            state.musicList = res.data.result;
        });
        return {state,changeCount}
    }
}
</script>

<style lang="less" scoped>
.musicList{ 
    width: 100%;
    .musicTop{
        display: flex;
        margin-top: .5rem;
        margin-left: .25rem;
        .title{
            width: 78%;
            font-weight: 700;
            font-size: .4rem;
        }
        .more{
            padding:.06rem .06rem;
            font-size: .28rem;
            border:1px solid rgba(0,0,0, .2);
            border-radius: .3rem;
        }
    }
    .musicSwipe{
        width: 100%;
        height: 5rem;
        margin-top: .2rem;
        .my-swipe{
            position: relative;
            height: 100%;
            margin-left: .2rem;
            img{
                width: 94%;
                height: 60%;
                border-radius: .2rem;
            }
            .playCount{
                position: absolute;
                top: .1rem;
                right: 0;
                width: 100%;
                height: 100%;
                color: rgba(255,255,255,.8);
                .iconfont{
                    font-size: .32rem;
                }
            }
            .name{
                display: inline-block;
                width: 100%;
                height: 100%;
                padding: .1rem .1rem;
                // overflow: hidden;
                // text-overflow: ellipsis; 
                // white-space: nowrap;
            }
        }
    }
}

</style>
